package procilege.impl.eval;

import java.util.Iterator;

import procilege.compute.ExprEvaluationTraveller;
import procilege.compute.PlaceTypeMetadata;
import procilege.compute.PlaceType;
import procilege.lang.BoolExprElement;
import procilege.lang.BoolExprOr;

@PlaceTypeMetadata(type = BoolExprOr.class)
public class BoolExprOrEvalPlace implements PlaceType<ExprEvaluationTraveller> {

	public void visit(ExprEvaluationTraveller tr, Object place) {

		BoolExprOr expr = (BoolExprOr) place;

		boolean r = false;

		Iterator<BoolExprElement> itr = expr.getTerms().iterator();
		while (!r && itr.hasNext()) {

			tr.setout(itr.next());
			Object val = tr.getPreviousVisitResult();
			if (!(val instanceof Boolean))
				throw new UnsupportedOperationException("mistype: "
						+ val.toString());

			r = r || (Boolean) val;
		}

		tr.result(r);
	}
}
